export function mostFrequentEven(nums: number[]): number {
    // TSError: ⨯ Unable to compile TypeScript:
    // leetCodeTypeScript/algorithm/mostFrequentEvenS2404.ts(10,24): error TS2802:
    // Type 'Map<number, number>' can only be iterated through
    // when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
    let count: Map<number, number> = new Map();
    for (let x of nums) {
        if (x % 2 === 0) {
            // js 是|| ts 可以用??
            count.set(x, (count.get(x) ?? 0) + 1);
        }
    }
    let res: number = -1, ct: number = 0;
    for (let [k, v] of count) {
        // 不用 res === -1 ||
        if (v > ct || v === ct && res > k) {
            res = k;
            ct = v;
        }
    }
    return res;
}
